package Easy中序遍历;

import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

public class Solution1 {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        inorder(root,list);
        return list;
    }

    public void inorder(TreeNode root,List<Integer> List){
        if (root != null) {
            inorder(root.left,List);
            List.add(root.val);
            inorder(root.right,List);
        }
    }

    @Test
    public void test(){
        TreeNode tree = new TreeNode(1,null,new TreeNode(2,new TreeNode(3),null));
        List<Integer> l = inorderTraversal(tree);
        for (Integer i:l
        ) {
            System.out.println(i);
        }
    }
}
